<?php
$uid = Yii::app()->user->id;
$address = UserAddress::model()->findByAttributes(array('uid' => $uid));
$user = User::model()->findByPk($uid);
//echo 'vinh show: '.ip();
?>
<fieldset id="billing_information">
    <legend>Billing Information</legend>
    <div class="form_fieldset">
        <table>
            <tr>
                <td style="width: 160px;">Billing Name:</td>
                <td style="width: 320px;"><?= ($user->display_name) ? $user->display_name : $user->username ?></td>
            </tr>
            <tr>
                <td>Billing Company:</td>
                <td><?= $address->company ?></td>
            </tr>
            <tr>
                <td>Billing Phone:</td>
                <td><?= $address->phone ?></td>
            </tr>
            <?php
            //Vinh note: xu ly nhung tinh huong user thay doi IP
            if ((ip() != $address->ipAddress) && (ip() != '127.0.0.1')) {
                ?>
                <tr><td colspan="2"><b>Bạn đang mua thẻ ở địa chỉ khác với địa chỉ lúc đăng ký
                            <br>Vui lòng cập nhật lại địa chỉ của bạn:</b>
                    </td></tr>
                <tr>
                    <td colspan="2">
                        <div id="notificationBilling"></div>   
                    </td>
                </tr>
                <tr>
                    <td>Billing Street:</td>
                    <td>
                        <?php echo $form->textField($model, 'billing_street', array('class' => 'form-text', 'value' => '')); ?> 
                        <span id="errorStreet" style="display: none;">Billling Street not blank</span>
                    </td>
                </tr>
                <tr>
                    <td>Billing City:</td>
                    <td>
                        <?php echo $form->textField($model, 'billing_city', array('class' => 'form-text', 'value' => '')); ?>
                        <span id="errorCity" style="display: none;">Billling City not blank</span>
                    </td>
                </tr>
                <tr>
                    <td>Billing Region:</td>
                    <td>
                        <?php echo $form->textField($model, 'billing_region', array('class' => 'form-text', 'value' => '')); ?>
                        <span id="errorRegion" style="display: none;">Billling Region not blank</span>
                    </td>
                </tr>
                <tr>
                    <td>Billing Zipcode:</td>
                    <td>
                        <?php echo $form->textField($model, 'billing_zipcode', array('class' => 'form-text', 'value' => '')); ?>
                        <span id="errorZip" style="display: none;">Billling Zipcode not blank</span>
                    </td>
                </tr>
                <input type="hidden" name="changebilling" value="1">
                <?php
            } else {
                echo $form->hiddenField($model, 'billing_street', array('value' => $address->street));
                echo $form->hiddenField($model, 'billing_city', array('value' => $address->city));
                echo $form->hiddenField($model, 'billing_region', array('value' => $address->region));
                echo $form->hiddenField($model, 'billing_zipcode', array('value' => $address->zipCode));
                echo $form->hiddenField($model, 'billing_country', array('value' => $address->countryCode));
                ?>
                <input type="hidden" name="changebilling" value="0">
                <tr>
                    <td>Billing Address:</td>
                    <td><?= $address->street . ', ' . $address->city . ', ' . $address->zipCode . ', ' . Countries::GetCountryName($address->countryCode) ?></td>
                </tr>
            <?php } ?>
        </table>
    </div>      
</fieldset>

<script type="text/javascript">
    /*
     $(document).ready(function(){
     var street = document.getElementById("CheckoutOrderForm_billing_street");
     if(street != null){
     alert('ban can dien dia chi');
     }
     });
     */
</script>

